var city = "泊头"

//https://bird.ioliu.cn/weather?city=成都     ---------天气网址
function loadXMLDoc() {
	var xmlhttp;
	if(window.XMLHttpRequest) {
		//  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp = new XMLHttpRequest();
	} else {
		// IE6, IE5 浏览器执行代码
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			//document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
			var json = xmlhttp.responseText;
			//把返回的数据转化为数组对象格式
			json = JSON.parse(json)
			console.log(json)
			var li = document.querySelectorAll(".ul li")
			//			console.log(li)
			for(var i = 0; i < li.length; i++) {
				li[i].children[0].innerHTML = json.daily_forecast[i].date.slice(5) + "日"
				li[i].children[1].innerHTML = json.daily_forecast[i].cond.txt_n
				li[i].children[2].innerHTML = json.daily_forecast[i].wind.dir
				li[i].children[3].children[0].innerHTML = json.daily_forecast[i].tmp.max + "℃"
				li[i].children[3].children[1].innerHTML = json.daily_forecast[i].tmp.min + "℃"
			}
			var li_1 = document.querySelectorAll(".days_1 li")
			//			console.log(li_1)
			
			for(var n = 0; n < li_1.length; n++) {
				li_1[n].children[0].innerHTML = json.hourly_forecast[n].tmp + "℃"
				li_1[n].children[1].innerHTML = json.hourly_forecast[n].wind.dir
				li_1[n].children[2].innerHTML = json.hourly_forecast[n].wind.sc + "级"
			}
			var li_2 = document.querySelectorAll(".days li")
			console.log(li_2)
			for(var j = 0; j < li_2.length; j++) {
				li_2[j].innerHTML = json.hourly_forecast[j].date.slice(11,13) + "时"
			}
			var lint = document.querySelector(".lin")
			console.log(lint)
			lint.children[0].children[1].innerHTML = json.suggestion.uv.brf
			lint.children[0].children[3].innerHTML = json.suggestion.uv.txt
			lint.children[1].children[3].innerHTML = json.suggestion.trav.txt
			lint.children[2].children[1].innerHTML = json.suggestion.sport.brf
			lint.children[2].children[3].innerHTML = json.suggestion.sport.txt
			lint.children[3].children[1].innerHTML = json.suggestion.drsg.brf
			lint.children[3].children[3].innerHTML = json.suggestion.drsg.txt
			lint.children[4].children[1].innerHTML = json.suggestion.cw.brf
			lint.children[4].children[3].innerHTML = json.suggestion.cw.txt
			lint.children[5].children[1].innerHTML = json.suggestion.air.brf
			lint.children[5].children[3].innerHTML = json.suggestion.air.txt

		}
	}
	xmlhttp.open("GET", "https://bird.ioliu.cn/weather?city=" + city, true);
	xmlhttp.send();
}
loadXMLDoc()

document.querySelector("#ipt").addEventListener('change', function() {
	console.log(this.value)
	//赋值城市
	city = this.value
	loadXMLDoc()
})